<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        body {
            background-color: #fff;
        }
    </style>
</head>
<body>
    <!-- 单击按钮，控制网页开关灯 -->
    <button class="btn">点击开关灯</button>
    <script>
        var btn = document.querySelector('.btn')
        var flag = true
        var bod = document.querySelector('body')
        btn.onclick = function (){
            if(flag) {
                bod.style.backgroundColor = '#000'
                flag = false
            } else {
                bod.style.backgroundColor = '#fff'
                flag = true
            }
        }

    </script>
</body>
</html>